import SimpleITK as sitk

for now in [6,7,8]:
    outTx=sitk.BSplineTransform( sitk.ReadTransform(str(now)+'reg3.mat') )
    print(outTx)
    fixed=sitk.ReadImage('Masked/'+str(now)+'masked.nii',sitk.sitkFloat32)
    toDisplacementFilter=sitk.TransformToDisplacementFieldFilter()
    toDisplacementFilter.SetReferenceImage(fixed)
    displacementField=toDisplacementFilter.Execute(outTx)
    print(displacementField)
    sitk.WriteImage(displacementField,'df3to'+str(now)+'.nii')#note displacementField is backward

    #same img but opposite order?